package com.jjyu.service.impl;

import com.jjyu.dao.RestaurantFavoriteMapper;
import com.jjyu.entity.RestaurantFavorite;
import com.jjyu.service.RestaurantFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class RestaurantFavoriteServiceImpl implements RestaurantFavoriteService {

    @Autowired
    private RestaurantFavoriteMapper restaurantFavoriteMapper;

    @Override
    public ResponseEntity<?> addFavorite(RestaurantFavorite favorite) {
        favorite.setAddedAt(LocalDateTime.now());
        if (restaurantFavoriteMapper.insert(favorite) > 0) {
            return ResponseEntity.ok().body(favorite);
        } else {
            return ResponseEntity.badRequest().body("Failed to add favorite");
        }
    }
}